import { selectors } from '../config.js';
import { BaseCardExtractor } from './base-card-extractor.js';

export class NewCardExtractor extends BaseCardExtractor {
  constructor() {
    super({
      card: selectors.newCard,
      name: selectors.newCardName,
      value: selectors.newCardValue,
      changeTitle: selectors.newCardChangeTitle,
      changeValue: selectors.newCardChangeValue
    });
  }

  // 重写提取值的方法，因为新版卡片有前缀
  extractValue(cardElement) {
    // 添加卡片标题标签
    const cardTitle = cardElement.querySelector(this.selectors.name)?.textContent.trim() || '新版卡片';
    const label = document.createElement('div');
    label.textContent = cardTitle;
    label.className = 'auto-new-card-label';
    label.style.cssText = `
      position: absolute;
      top: -25px;
      left: 50%;
      transform: translateX(-50%);
      font-size: 16px;
      font-weight: bold;
      color: #00a854;
      background: #f5f5f5;
      border: 2px solid #00a854;
      border-radius: 0;
      padding: 2px 6px;
      z-index: 9999;
      pointer-events: none;
    `;
    cardElement.style.position = 'relative';
    cardElement.appendChild(label);

    // 添加卡片样式
    cardElement.style.backgroundColor = 'hsla(120, 70%, 80%, 0.3)';
    cardElement.style.border = '1px solid #00a854';
    cardElement.style.borderRadius = '6px';
    cardElement.style.padding = '8px';
    cardElement.style.margin = '4px 0';

    const valuePrefix = cardElement.querySelector(selectors.newCardValuePrefix)?.textContent.trim() || '';
    const value = cardElement.querySelector(this.selectors.value)?.textContent.trim() || '';
    return valuePrefix + value;
  }

  // 重写提取变化数据的方法，因为新版卡片有图标判断
  extractChangeData(cardElement) {
    const changeTitle = cardElement.querySelector(this.selectors.changeTitle)?.textContent.trim();
    const changeValue = cardElement.querySelector(this.selectors.changeValue)?.textContent.trim();
    const changeIcon = cardElement.querySelector(selectors.newCardChangeIcon);
    
    if (changeTitle && changeValue) {
      if (changeIcon || changeValue !== '--') {
        return { [changeTitle]: changeValue };
      }
    }
    return {};
  }
} 